﻿package mortal.game.scene3D.layer3D.utils
{
    import Message.BroadCast.*;
    import Message.Public.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.rules.*;
    import mortal.game.scene3D.layer3D.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.scene3D.player.item.*;
    import mortal.game.utils.*;

    public class DropItemUtil extends EntityLayerUtil
    {
        private var _dropItemMap:DropItemDictionary;
        private var _simpleItemMap:Dictionary;

        public function DropItemUtil(param1:PlayerLayer)
        {
            this._dropItemMap = new DropItemDictionary();
            this._simpleItemMap = new Dictionary();
            super(param1);
            return;
        }// end function

        public function get dropItemMap() : DropItemDictionary
        {
            return this._dropItemMap;
        }// end function

        public function addDropItems(param1:Array) : void
        {
            var _loc_2:SDropEntityInfo = null;
            for each (_loc_2 in param1)
            {
                
                this.addDropItem(_loc_2);
            }
            return;
        }// end function

        public function addDropItem(param1:SDropEntityInfo) : void
        {
            if (!isCanSelfGet(param1) && param1.dropDt.time + 60000 <= ClockManager.instance.nowDate.time)
            {
                return;
            }
            var _loc_2:* = EntityClass.getInstanceByType(EntityType.DropItem) as ItemPlayer;
            _loc_2.dropEntityInfo = param1;
            this._dropItemMap.addDropItem(param1.entityId, _loc_2);
            layer.addChild(_loc_2);
            return;
        }// end function

        public function removeDropItem(param1:SEntityId) : ItemPlayer
        {
            var _loc_2:* = this._dropItemMap.removeDropItem(param1);
            if (_loc_2)
            {
                _loc_2.dispose();
            }
            return _loc_2;
        }// end function

        public function getDropItem(param1:SEntityId) : ItemPlayer
        {
            return this._dropItemMap.getDropItem(param1);
        }// end function

        public function getDorpItemByItemCode(param1:int) : ItemPlayer
        {
            return this._dropItemMap.getDropItemByItemCode(param1);
        }// end function

        public function getDorpItemByItemUnit(param1:int) : ItemPlayer
        {
            return this._dropItemMap.getDropItemByItemUnit(param1);
        }// end function

        public function getRandomDropItem(param1:Boolean = false) : ItemPlayer
        {
            var _loc_2:* = this._dropItemMap.getRandomDropItem(param1);
            return _loc_2;
        }// end function

        override public function removeAll() : void
        {
            var _loc_1:ItemPlayer = null;
            for each (_loc_1 in this._dropItemMap.map)
            {
                
                if (_loc_1)
                {
                    _loc_1.dispose();
                }
            }
            this._dropItemMap.removeAll();
            return;
        }// end function

        override public function updateEntity() : void
        {
            var _loc_2:ItemPlayer = null;
            var _loc_1:* = this._dropItemMap.map;
            for each (_loc_2 in _loc_1)
            {
                
                if (SceneRange.isInScene(_loc_2.x2d, _loc_2.y2d))
                {
                    if (layer.contains(_loc_2) == false)
                    {
                        layer.addChild(_loc_2);
                    }
                    continue;
                }
                if (layer.contains(_loc_2))
                {
                    layer.removeChild(_loc_2);
                }
            }
            return;
        }// end function

        public function onClickScene() : ItemPlayer
        {
            return null;
        }// end function

        public static function isCanSelfGet(param1:SDropEntityInfo) : Boolean
        {
            if (!CopyUtil.isInTeamDefenseCopy && !EntityUtil.equal(param1.ownerEntityId, Cache.instance.role.entityInfo.entityId) && param1.ownerEntityId.type == EEntityType._EEntityTypePlayer)
            {
                return false;
            }
            return true;
        }// end function

    }
}
